package com.guofen.controller.sjq;


import com.guofen.pojo.SjqDeodorizationRunningOne;
import com.guofen.service.sjq.SjqDeodorizationRunningOneService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/sjq/SjqDeodorizationRunningOne")
@Controller
@Api(tags = "SjqDeodorizationRunningOneController", description = "固液分离除臭塔运行记录表")
public class SjqDeodorizationRunningOneController {

    @Autowired
    private SjqDeodorizationRunningOneService sjqDeodorizationRunningOneService;

    @ApiOperation("添加记录")
    @RequestMapping(value = "/addForm", method = RequestMethod.POST)
    @ResponseBody
    public Result addForm(@ApiParam(name = "dosingTime1", value = "固液分离1#除臭塔-添加时间-加药", required = true) @RequestParam String dosingTime1,
                          @ApiParam(name = "waterTime1", value = "固液分离1#除臭塔-添加时间-加水", required = true) @RequestParam String waterTime1,
                          @ApiParam(name = "drugName1", value = "固液分离1#除臭塔-药剂名称", required = true) @RequestParam String drugName1,
                          @ApiParam(name = "dosage1", value = "固液分离1#除臭塔-药剂使用量（kg）", required = true) @RequestParam String dosage1,
                          @ApiParam(name = "isScaleMark1", value = "固液分离1#除臭塔-加水量是否到规定刻度线", required = true) @RequestParam String isScaleMark1,
                          @ApiParam(name = "nozzlePipelineCleanTime1", value = "固液分离1#除臭塔-喷嘴，管路清洗时间", required = true) @RequestParam String nozzlePipelineCleanTime1,
                          @ApiParam(name = "nozzlePipelineCleanCondition1", value = "固液分离1#除臭塔-喷嘴，管路清洗情况", required = true) @RequestParam String nozzlePipelineCleanCondition1,
                          @ApiParam(name = "packingCleaningTime1", value = "固液分离1#除臭塔-填料-清洗时间", required = true) @RequestParam String packingCleaningTime1,
                          @ApiParam(name = "packingReplacementTime1", value = "固液分离1#除臭塔-填料-更换时间", required = true) @RequestParam String packingReplacementTime1,
                          @ApiParam(name = "dosingTime2", value = "固液分离2#除臭塔-添加时间-加药", required = true) @RequestParam String dosingTime2,
                          @ApiParam(name = "waterTime2", value = "固液分离2#除臭塔-添加时间-加水", required = true) @RequestParam String waterTime2,
                          @ApiParam(name = "drugName2", value = "固液分离2#除臭塔-药剂名称", required = true) @RequestParam String drugName2,
                          @ApiParam(name = "dosage2", value = "固液分离2#除臭塔-药剂使用量（kg）", required = true) @RequestParam String dosage2,
                          @ApiParam(name = "isScaleMark2", value = "固液分离2#除臭塔-加水量是否到规定刻度线", required = true) @RequestParam String isScaleMark2,
                          @ApiParam(name = "nozzlePipelineCleanTime2", value = "固液分离2#除臭塔-喷嘴，管路清洗时间", required = true) @RequestParam String nozzlePipelineCleanTime2,
                          @ApiParam(name = "nozzlePipelineCleanCondition2", value = "固液分离2#除臭塔-喷嘴，管路清洗情况", required = true) @RequestParam String nozzlePipelineCleanCondition2,
                          @ApiParam(name = "packingCleaningTime2", value = "固液分离2#除臭塔-填料-清洗时间", required = true) @RequestParam String packingCleaningTime2,
                          @ApiParam(name = "packingReplacementTime2", value = "固液分离2#除臭塔-填料-更换时间", required = true) @RequestParam String packingReplacementTime2,
                          @ApiParam(name = "reportTime", value = "发现问题反映给技术部时间", required = true) @RequestParam String reportTime,
                          @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator,
                          @ApiParam(name = "remarks", value = "备注", required = false) @RequestParam String remarks){
        double d1 = Double.parseDouble(dosage1);
        double d2 = Double.parseDouble(dosage2);


        if (sjqDeodorizationRunningOneService.addForm(dosingTime1,waterTime1,drugName1,d1,isScaleMark1,nozzlePipelineCleanTime1,nozzlePipelineCleanCondition1,packingCleaningTime1,
                packingReplacementTime1,dosingTime2,waterTime2,drugName2,d2,isScaleMark2,nozzlePipelineCleanTime2,nozzlePipelineCleanCondition2,packingCleaningTime2,
                packingReplacementTime2,reportTime,operator,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("查询记录")
    @RequestMapping(value = "/getLast", method = RequestMethod.GET)
    @ResponseBody
    public Result getLast(){
        if (sjqDeodorizationRunningOneService.findForm() != null)
            return ResultGenerator.genSuccessResult(sjqDeodorizationRunningOneService.findForm());
        else
            return ResultGenerator.genFailResult("暂无记录");
    }


    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqDeodorizationRunningOneService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id,
                         @ApiParam(name = "dosingTime1", value = "固液分离1#除臭塔-添加时间-加药", required = true) @RequestParam String dosingTime1,
                         @ApiParam(name = "waterTime1", value = "固液分离1#除臭塔-添加时间-加水", required = true) @RequestParam String waterTime1,
                         @ApiParam(name = "drugName1", value = "固液分离1#除臭塔-药剂名称", required = true) @RequestParam String drugName1,
                         @ApiParam(name = "dosage1", value = "固液分离1#除臭塔-药剂使用量（kg）", required = true) @RequestParam String dosage1,
                         @ApiParam(name = "isScaleMark1", value = "固液分离1#除臭塔-加水量是否到规定刻度线", required = true) @RequestParam String isScaleMark1,
                         @ApiParam(name = "nozzlePipelineCleanTime1", value = "固液分离1#除臭塔-喷嘴，管路清洗时间", required = true) @RequestParam String nozzlePipelineCleanTime1,
                         @ApiParam(name = "nozzlePipelineCleanCondition1", value = "固液分离1#除臭塔-喷嘴，管路清洗情况", required = true) @RequestParam String nozzlePipelineCleanCondition1,
                         @ApiParam(name = "packingCleaningTime1", value = "固液分离1#除臭塔-填料-清洗时间", required = true) @RequestParam String packingCleaningTime1,
                         @ApiParam(name = "packingReplacementTime1", value = "固液分离1#除臭塔-填料-更换时间", required = true) @RequestParam String packingReplacementTime1,
                         @ApiParam(name = "dosingTime2", value = "固液分离2#除臭塔-添加时间-加药", required = true) @RequestParam String dosingTime2,
                         @ApiParam(name = "waterTime2", value = "固液分离2#除臭塔-添加时间-加水", required = true) @RequestParam String waterTime2,
                         @ApiParam(name = "drugName2", value = "固液分离2#除臭塔-药剂名称", required = true) @RequestParam String drugName2,
                         @ApiParam(name = "dosage2", value = "固液分离2#除臭塔-药剂使用量（kg）", required = true) @RequestParam String dosage2,
                         @ApiParam(name = "isScaleMark2", value = "固液分离2#除臭塔-加水量是否到规定刻度线", required = true) @RequestParam String isScaleMark2,
                         @ApiParam(name = "nozzlePipelineCleanTime2", value = "固液分离2#除臭塔-喷嘴，管路清洗时间", required = true) @RequestParam String nozzlePipelineCleanTime2,
                         @ApiParam(name = "nozzlePipelineCleanCondition2", value = "固液分离2#除臭塔-喷嘴，管路清洗情况", required = true) @RequestParam String nozzlePipelineCleanCondition2,
                         @ApiParam(name = "packingCleaningTime2", value = "固液分离2#除臭塔-填料-清洗时间", required = true) @RequestParam String packingCleaningTime2,
                         @ApiParam(name = "packingReplacementTime2", value = "固液分离2#除臭塔-填料-更换时间", required = true) @RequestParam String packingReplacementTime2,
                         @ApiParam(name = "reportTime", value = "发现问题反映给技术部时间", required = true) @RequestParam String reportTime,
                         @ApiParam(name = "operator", value = "操作人", required = true) @RequestParam String operator,
                         @ApiParam(name = "remarks", value = "备注", required = false) @RequestParam String remarks) {
        SjqDeodorizationRunningOne sjqDeodorizationRunningOne = new SjqDeodorizationRunningOne();
        double d1 = Double.parseDouble(dosage1);
        double d2 = Double.parseDouble(dosage2);
        sjqDeodorizationRunningOne.setId(id);
        sjqDeodorizationRunningOne.setDosingTime1(dosingTime1);
        sjqDeodorizationRunningOne.setWaterTime1(waterTime1);
        sjqDeodorizationRunningOne.setDrugName1(drugName1);
        sjqDeodorizationRunningOne.setDosage1(d1);
        sjqDeodorizationRunningOne.setIsScaleMark1(isScaleMark1);
        sjqDeodorizationRunningOne.setNozzlePipelineCleanTime1(nozzlePipelineCleanTime1);
        sjqDeodorizationRunningOne.setNozzlePipelineCleanCondition1(nozzlePipelineCleanCondition1);
        sjqDeodorizationRunningOne.setPackingCleaningTime1(packingCleaningTime1);
        sjqDeodorizationRunningOne.setPackingReplacementTime1(packingReplacementTime1);
        sjqDeodorizationRunningOne.setDosingTime2(dosingTime2);
        sjqDeodorizationRunningOne.setWaterTime2(waterTime2);
        sjqDeodorizationRunningOne.setDrugName2(drugName2);
        sjqDeodorizationRunningOne.setDosage2(d2);
        sjqDeodorizationRunningOne.setIsScaleMark2(isScaleMark2);
        sjqDeodorizationRunningOne.setNozzlePipelineCleanTime2(nozzlePipelineCleanTime2);
        sjqDeodorizationRunningOne.setNozzlePipelineCleanCondition2(nozzlePipelineCleanCondition2);
        sjqDeodorizationRunningOne.setPackingCleaningTime2(packingCleaningTime2);
        sjqDeodorizationRunningOne.setPackingReplacementTime2(packingReplacementTime2);
        sjqDeodorizationRunningOne.setReportTime(reportTime);
        sjqDeodorizationRunningOne.setOperator(operator);
        sjqDeodorizationRunningOne.setRemarks(remarks);
        return ResultGenerator.genSuccessResult(sjqDeodorizationRunningOneService.update(sjqDeodorizationRunningOne));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间") Long startTime,
                         @ApiParam(name="endTime",value="截止时间") Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqDeodorizationRunningOneService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqDeodorizationRunningOneService.getByTime(pageSize, currentPage, startTime, endTime));
    }

}
